using System.Collections.Generic;
using System.Drawing;
using dk.Helper.Base;
using dk.Helper.Base.Core;
using NUnit.Framework;

namespace dk.Helper.Test
{
    [TestFixture]
    public class VillageGroupsTest
    {
        private const string GROUP_NAME = "Group Name";
        private IVillage dummyVillage;
        private IVillageGroups villageGroups;
        private IGroupType groupType;
        private IVillageGroup villageGroup;

        [SetUp]
        public void SetUp()
        {
            this.dummyVillage = new Village(0, string.Empty, new Point(0, 0), 0, 0, 0);
            this.villageGroups = new VillageGroups(this.dummyVillage);
            this.groupType = new GroupType();
            this.villageGroup = new VillageGroup(GROUP_NAME, groupType);
        }

        [Test]
        public void Groups_NotNull()
        {
            Assert.IsNotNull(villageGroups.Groups);
        }

        [Test]
        public void Village_NotNull()
        {
            Assert.IsNotNull(villageGroups.Village);
        }

        [Test]
        public void Contains()
        {
            villageGroups.Groups.Add(this.villageGroup.Name, this.villageGroup);
            Assert.IsTrue(villageGroups.Contains(villageGroup));
        }

        [Test]
        public void NotContains()
        {
            Assert.IsFalse(villageGroups.Contains(villageGroup));
        }

        [Test]
        public void AddGroup()
        {
            villageGroups.AddGroup(this.villageGroup);
            Assert.IsTrue(villageGroups.Groups.ContainsKey(GROUP_NAME));
        }

        [Test]
        public void RemoveGroup()
        {
            villageGroups.Groups.Add(villageGroup.Name, villageGroup);
            villageGroups.RemoveGroup(villageGroup);
            Assert.IsFalse(villageGroups.Contains(villageGroup));
        }

        [Test]
        public void RemoveGroupByName()
        {
            villageGroups.Groups.Add(this.villageGroup.Name, this.villageGroup);
            villageGroups.RemoveGroup(this.villageGroup.Name);
            Assert.IsFalse(villageGroups.Contains(this.villageGroup));
        }

        [Test]
        public void VillageGroupContainsVillageAfterAddGroup()
        {
            IVillageGroups groups = new VillageGroups(this.dummyVillage);
            groups.AddGroup(this.villageGroup);
            Assert.IsTrue(groups.Groups[GROUP_NAME].Villages.Contains(this.dummyVillage));
        }

        [Test]
        public void VillageGroupNotContainsVillageAfterRemoveGroup()
        {
            IVillageGroups groups = new VillageGroups(this.dummyVillage);
            groups.AddGroup(this.villageGroup);
            groups.RemoveGroup(this.villageGroup);
            Assert.IsFalse(this.villageGroup.Villages.Contains(this.dummyVillage));
        }

        [Test]
        public void GroupsOrder1()
        {
            this.villageGroups.AddGroup(new VillageGroup("Group 1", new GroupType { Order = 2 }));
            IVillageGroup villageGroup2 = new VillageGroup("Group 2", new GroupType { Order = 1 });
            this.villageGroups.AddGroup(villageGroup2);
            this.villageGroups.AddGroup(new VillageGroup("Group 3", new GroupType { Order = 3 }));
            IList<IVillageGroup> groups = villageGroups.GetGroupsByOrder(1);
            Assert.IsTrue(groups.Contains(villageGroup2));
        }

        [Test]
        public void GroupsOrder2()
        {
            IVillageGroup villageGroup1 = new VillageGroup("Group 1", new GroupType { Order = 2 });
            this.villageGroups.AddGroup(villageGroup1);
            this.villageGroups.AddGroup(new VillageGroup("Group 2", new GroupType { Order = 1 }));
            this.villageGroups.AddGroup(new VillageGroup("Group 3", new GroupType { Order = 3 }));
            IList<IVillageGroup> groups = villageGroups.GetGroupsByOrder(2);
            Assert.IsTrue(groups.Contains(villageGroup1));
        }

        [Test]
        public void GroupsOrder3()
        {
            this.villageGroups.AddGroup(new VillageGroup("Group 1", new GroupType { Order = 2 }));
            this.villageGroups.AddGroup(new VillageGroup("Group 2", new GroupType { Order = 1 }));
            IVillageGroup villageGroup3 = new VillageGroup("Group 3", new GroupType { Order = 3 });
            this.villageGroups.AddGroup(villageGroup3);
            IList<IVillageGroup> groups = villageGroups.GetGroupsByOrder(3);
            Assert.IsTrue(groups.Contains(villageGroup3));
        }
    }
}
